package com.superman.supermarket.client.composite.home.storelist;

import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.ui.FlowPanel;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.mvpframe.client.utils.XJsonUtil;

/**
 * 首页推荐店铺列表模块
 * 
 * @author superman
 * @version 2018年7月21日下午9:07:36
 */
public class RecommandStoreListModule extends FlowPanel {

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月2日 下午10:04:32
	 */
	public RecommandStoreListModule() {
		getRecommandStoreList();
	}

	private void getRecommandStoreList() {
		XGinjector.INSTANCE.getPostMan().post("/store/queryStores", null, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				if (XJsonUtil.getCount(response) > 0) {
					List<Map<String, Object>> list = XJsonUtil.getList(response);
					for (Map<String, Object> map : list) {
						StoreListModule storeListModule = new StoreListModule();
						storeListModule.getElement().getStyle().setProperty("marginBottom", "0.1333333rem");
						RecommandStoreListModule.this.add(storeListModule);
						storeListModule.setData(map);
					}
				} else {
					RecommandStoreListModule.this.removeFromParent();
				}
			}
		});
	}
}
